<?php
/**
 * 简单工厂模式
 * This file is part of pattern.
 * Author: tangzhou
 * Date: 2016/8/26
 * Time: 10:24
 * File: SimpleFactory.php
 */

/**
 * 抽象产品角色
 * Interface Product
 */
interface Product
{
    /**
     * X轴旋转产品
     * @return mixed
     */
    function XRotate();

    /**
     * Y轴旋转产品
     * @return mixed
     */
    function YRotate();
}

/**
 * Class XProduct
 */
class XProduct implements Product
{
    private $xMax = 1;
    private $yMax = 1;

    public function __construct($xMax = 1, $yMax = 1)
    {
        $this->xMax = $xMax;
        $this->yMax = $yMax;
    }

    function XRotate()
    {
        echo "我能X轴旋转---".$this->xMax;
    }

    function YRotate()
    {
        echo "我Y轴是不能旋转---".$this->yMax;
    }
}

/**
 * Class YProduct
 */
class YProduct implements Product
{
    private $xMax = 1;
    private $yMax = 1;

    public function __construct($xMax = 1, $yMax = 1)
    {
        $this->xMax = $xMax;
        $this->yMax = $yMax;
    }

    function XRotate()
    {
        echo "我能X轴不能旋转---".$this->xMax;
    }

    function YRotate()
    {
        echo "我Y轴能旋转---".$this->yMax;
    }
}

/**
 * 工厂方法
 * Class ProductFactory
 */
class ProductFactory
{
    static function GetInstance($xMax, $yMax)
    {
        if ($xMax > 1 ){
            return new XProduct($xMax, 1);
        } elseif ($yMax > 1) {
            return new YProduct($yMax, 1);
        } else {
            return null;
        }
    }
}